﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FredCK.FCKeditorV2;
using WebAsp.DTO;
using WebAsp.DAL;

namespace WebAsp.Admin.News
{
    public partial class Editor : System.Web.UI.UserControl
    {
        public NewsDTO getInformation = new NewsDTO();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
                getInformation = new NewsDTO(txtTitle.Text, txtSummary.Text, txtContent.Value, txtImgUrl.Text, int.Parse(cbbCategory.SelectedValue));
            cbbCategory.DataSource = NewsCatDAL.GetList();
            cbbCategory.DataTextField = "Name";
            cbbCategory.DataValueField = "ID";
            cbbCategory.DataBind();

            if (Request.QueryString["ID"] != null)
            {
                NewsDTO item = NewsDAL.GetItem(int.Parse(Request.QueryString["ID"]));
                if (!IsPostBack)
                {
                    cbbCategory.Items.FindByText(item.CategoryName).Selected = true;
                    cbbCategory.Text = item.CategoryName;
                    txtImgUrl.Text = item.ImagesLink;
                    txtTitle.Text = item.Title;
                    txtSummary.Text = item.Summary;
                    txtContent.Value = item.Contents;
                }
                else
                {
                    getInformation.ID = int.Parse(Request.QueryString["ID"]);
                }
            }
        }
    }
}